package com.sg.service.biz.bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.exception.Assert;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.req.BffQueryBizAppSceneMenuListReqDto;
import com.sg.dto.biz.bff.req.BffQueryBizSceneMenuListReqDto;
import com.sg.dto.biz.bff.res.BffQueryBizAppSceneMenuListRespDto;
import com.sg.dto.biz.bff.res.BffQueryBizSceneMenuListRespDto;
import com.sg.service.biz.bff.AppSceneService;
import com.sg.service.biz.bff.nb.NbAppScene;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class AppSceneServiceImpl implements AppSceneService {

    @Resource
    AppSceneService fwBaseAppSceneClient;
    @Resource
    com.sg.service.biz.framework.HostTypeService fwBaseHostTypeClient;
    @Resource
    com.sg.service.biz.framework.DivineDataService fwBaseDivineDataClient;
    @Resource
    NbAppScene nbAppScene;
    @Resource
    com.sg.service.biz.framework.InductionRecordService fwBaseInductionRecordClient;
    @Resource
    private RedisUtil redisUtil;


    /**
     * B1-1查询业务场景列表（边界）	[770]
     * gen by moon at 8/10/2022, 3:30:23 AM
     */
    @Trace(operationName = "B1-1查询业务场景列表（边界）	")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryBizSceneMenuListRespDto queryBizSceneMenuList(BffQueryBizSceneMenuListReqDto reqDto) {


        QueryBizSceneListRespDto queryBizSceneListRespDto_1 = null;
//步骤0: D1-1查询业务场景列表 - queryBizSceneList
        QueryBizSceneListRespDto queryBizSceneListRespDto = null;
        QueryBizSceneListReqDto queryBizSceneListReqDto = new QueryBizSceneListReqDto();
        queryBizSceneListReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:33202_1
        if (reqDto != null) {
            queryBizSceneListReqDto.setBizAppId(reqDto.getBizAppId());//sourceId:33200_1
        }

        /*D1-1查询业务场景列表[753]   */
        Assert.isNull(queryBizSceneListReqDto.getBizAppId(), "B1-1查询业务场景列表（边界）	-D1-1查询业务场景列表-业务应用ID不能为空", false);
        Assert.isNull(queryBizSceneListReqDto.getSubjectLifeCycle(), "B1-1查询业务场景列表（边界）	-D1-1查询业务场景列表-主体生命周期不能为空", false);
        queryBizSceneListRespDto = fwBaseAppSceneClient.queryBizSceneList(queryBizSceneListReqDto).getData();

        queryBizSceneListRespDto_1 = queryBizSceneListRespDto;

        BffQueryBizSceneMenuListRespDto retData = new BffQueryBizSceneMenuListRespDto();
        if (queryBizSceneListRespDto_1 != null) {
            retData.setBizSceneList(queryBizSceneListRespDto_1.getBizSceneList().stream().map(item -> BeanUtil.toBean(item, BffBizSceneDto.class)).collect(Collectors.toList()));//sourceId:33205_1
        }


        return retData;
    }

    /**
     * B1-1查询业务应用菜单列表（边界）[766]
     */
    @Trace(operationName = "B1-1查询业务应用菜单列表（边界）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryBizAppSceneMenuListRespDto queryBizAppSceneMenuList(BffQueryBizAppSceneMenuListReqDto reqDto) {


        //步骤0: D1-1查询业务应用菜单列表（边界） - queryBizAppSceneMenuList
        QueryBizAppSceneMenuListRespDto queryBizAppSceneMenuListRespDto = null;
        QueryBizAppSceneMenuListReqDto queryBizAppSceneMenuListReqDto = new QueryBizAppSceneMenuListReqDto();


        /*D1-1查询业务应用菜单列表（边界）[1441]   */
        queryBizAppSceneMenuListRespDto = fwBaseAppSceneClient.queryBizAppSceneMenuList(queryBizAppSceneMenuListReqDto).getData();


        BffQueryBizAppSceneMenuListRespDto retData = new BffQueryBizAppSceneMenuListRespDto();
        retData.setBizAppSceneList(queryBizAppSceneMenuListRespDto.getBizAppSceneList().stream().map(item -> BeanUtil.toBean(item, BffBizAppSceneDto.class)).collect(Collectors.toList()));//sourceId:34355_1


        return retData;
    }


}
